Android-gradle-localization-plugin

Gradle plugin for generating localized string resources


Project maintained by koral-- Hosted on GitHub Pages — Theme by mattgraham

android-gradle-localization-plugin

Maven Central Android Arsenal Build Status

Gradle plugin for generating localized string resources

Overview

This plugin generates Android string resource XML files from CSV file. Generation has to be invoked as additional gradle task.

Supported features

Usage

  1. Add dependency to the top-level build.gradle file. Your file should look like this:

    
    buildscript {
       repositories {
           mavenLocal()
           mavenCentral()
       }
       dependencies {
           classpath 'com.android.tools.build:gradle:0.13.+'
           classpath 'pl.droidsonroids.gradle.localization:android-gradle-localization-plugin:1.0.+'
       }
    }
    
  2. Apply plugin and add configuration to build.gradle of the application, eg:

    apply plugin: 'localization'
    localization
       {
           csvFile=file('translations.csv')
           OR
           csvFileURI='https://docs.google.com/spreadsheets/d/<key>/export?format=csv'
       }
    

    csvFileURI can be any valid URI, not necessarily Google Docs' one

  3. Invoke localization gradle task. Task may be invoked from commandline or from Android Studio GUI.

    • from commandline: ./gradlew localization (or gradlew.bat localization on Windows)
    • from GUI: menu View->Tool Windows->Gradle and double click localization

    Non existent folders will be created. WARNING existing XML files will be overwritten.

Example

The following CSV file:

name,default    ,pl       ,comment   ,translatable
file,File       ,"Plik"   ,file label,
app ,Application,,,false

will produce 2 XML files:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
  <string name="file">File</string><!-- file label -->
  <string name="app" translatable="false">Application</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
  <string name="file">Plik</string><!-- file label -->
</resources>

Configuration

localization extension in build.gradle can contain several configuration options. All of them except CSV file location are optional and has reasonable default values.
CSV file location. Exactly one of them must be specified:

CSV format:

The following options turn off some character escaping and substitutions, can be useful if you have something already escaped in CSV:

Advanced options:

License

MIT License
See LICENSE file.